package com.dhl.college.service.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dhl.college.service.edu.entity.Teacher;
import com.dhl.college.service.edu.entity.vo.TeacherQueryVo;
import com.dhl.college.service.edu.mapper.TeacherMapper;
import com.dhl.college.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author dhl
 * @since 2020-10-08
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Override
    public IPage<Teacher> selectPage(Page<Teacher> teacherPage, TeacherQueryVo teacherQueryVo) {
        //显示分页查询列表
        //1、排序：按照sort字段排序
        QueryWrapper<Teacher> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByAsc("sort");
        //2、查询(如果条件查询为空，则直接分页查询即可)
        if(teacherQueryVo==null){
            //只分页排序
            return baseMapper.selectPage(teacherPage,queryWrapper);
        }
        //3、条件查询(有条件，就封装条件)
        String name = teacherQueryVo.getName();
        Integer level = teacherQueryVo.getLevel();
        String joinDateBegin = teacherQueryVo.getJoinDateBegin();
        String joinDateEnd = teacherQueryVo.getJoinDateEnd();
        if(!StringUtils.isEmpty(name)){
            queryWrapper.likeRight("name",name);
        }
        if(level!=null){
            queryWrapper.eq("level",level);
        }
        if(!StringUtils.isEmpty(joinDateBegin)){
            queryWrapper.ge("join_data",joinDateBegin);
        }
        if(!StringUtils.isEmpty(joinDateEnd)){
            queryWrapper.le("join_data",joinDateEnd);
        }
        return baseMapper.selectPage(teacherPage,queryWrapper);
    }
}
